// pages/myapiary/details/details.js
import http from '../../http/http.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    fx: true,
    yj: false,
    showFc: true,
    boobox: {},
    id: '',
    ids: '',
    info: '',
    warmlist: {},
    alertpop: false,
    popmes: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.id = options.id
    if (options.type) {
      this.setData({
        fc: false,
        fx: true,
        yj: false,
      })
    }
  },
  onShow: function () {
    this.beebox()
    this.warmlist()
  },
  
  // 蜂箱列表
  beebox: function () {
    http.getdata('/api/beehive/list').then((res) => {
      this.setData({
        boobox: res.data.result
      })
    })
  },
  // 预警列表
  warmlist: function () {
    http.getdata('/api/monitor/list?status=1').then((res) => {
      this.setData({
        warmlist: res.data.result
      })
    })
  },
  toaddbeebox:function(){
    wx.redirectTo({
      url: '../beebox/add/addbeebox?type=add&showtoast=' + false,
    })
  },
  fx_tab: function () {
    this.setData({
      fx: true,
      yj: false,
    })

  },
  yj_tab: function () {
    this.setData({
      fx: false,
      yj: true,
    })
  },
  bee_box_details: function (e) {
    let deviceCode = e.currentTarget.dataset.devicecode
    console.log(e)
    wx.navigateTo({
      url: '../beebox/detail/index?deviceCode='+deviceCode,
    })
  },
  viewbee: function (e) {
    let idd = e.currentTarget.dataset.id
    let mesage = e.currentTarget.dataset.message
    this.setData({
      alertpop: true,
      popmes: mesage,
      ids: idd
    })
  },
  // 关闭查看
  closepop: function () {
    let pars = {
      id: this.data.ids
    }
    http.putdata('/api/monitor/process', pars).then((res) => {
      this.setData({
        alertpop: false
      })
      this.warmlist()
    })
  }
})